package com.tank.config;

import java.awt.image.BufferedImage;
import java.util.EnumMap;
import java.util.Map;

import com.tank.common.Dir;
import com.tank.util.ImageUtils;

/**
 * TODO
 *
 * @author chenwb
 * @since 2024/1/26 22:43
 */

public class ResourceMgr {
    /**
     * 坦克图片
     */
    private static final BufferedImage TANK_IMAGE = ImageUtils.loadImage(TankConfig.DEFAULT_TANK_IMAGE_PATH);

    private static final Map<Dir, BufferedImage> TANK_IMAGES = new EnumMap<>(Dir.class);

    static {
        TANK_IMAGES.put(Dir.UP, TANK_IMAGE);
        TANK_IMAGES.put(Dir.DOWN, ImageUtils.rotateImage(TANK_IMAGE, 180));
        TANK_IMAGES.put(Dir.LEFT, ImageUtils.rotateImage(TANK_IMAGE, 270));
        TANK_IMAGES.put(Dir.RIGHT, ImageUtils.rotateImage(TANK_IMAGE, 90));
    }


    public static BufferedImage getTankImage(Dir direction) {
        return TANK_IMAGES.get(direction);
    }

    private static final BufferedImage ENEMY_TANK_IMAGE = ImageUtils.loadImage(TankConfig.DEFAULT_ENEMY_TANK_IMAGE_PATH);

    public static BufferedImage getEnemyTankImage() {
        return ENEMY_TANK_IMAGE;
    }
    private static final BufferedImage BULLET_IMAGE = ImageUtils.loadImage(TankConfig.DEFAULT_BULLET_IMAGE_PATH);
    private static final Map<Dir, BufferedImage> BULLET_IMAGES = new EnumMap<>(Dir.class);
    public static BufferedImage getBulletImage(Dir dir) {
        return BULLET_IMAGES.get(dir);
    }
    static {
        BULLET_IMAGES.put(Dir.UP, BULLET_IMAGE);
        BULLET_IMAGES.put(Dir.DOWN, ImageUtils.rotateImage(BULLET_IMAGE, 180));
        BULLET_IMAGES.put(Dir.LEFT, ImageUtils.rotateImage(BULLET_IMAGE, 270));
        BULLET_IMAGES.put(Dir.RIGHT, ImageUtils.rotateImage(BULLET_IMAGE, 90));
    }

    private static final BufferedImage[] EXPLODE_IMAGES = new BufferedImage[16];

    static {
        for (int i = 0; i < EXPLODE_IMAGES.length; i++) {
            EXPLODE_IMAGES[i] = ImageUtils.loadImage("/static/images/e" + (i + 1) + ".gif");
        }
    }

    public static BufferedImage[] getExplodeImages() {
        return EXPLODE_IMAGES;
    }

}